<template>
  <div class="collect-container">
    <van-icon
      @click="attitudehandle"
      :class="{ activeCollect: attitude==1?true:false }"
      name="good-job"
    />=={{ attitude }}
  </div>
</template>

<script>
import { mapState } from "vuex";

import { deleteLikeApi, addLikeApi } from "@/api";
export default {
  //props: ["article"],
  model: {
    prop: "attitude", //  value
    event: "qqq" //  input
  },
  props: {
    attitude: {
      type: [Boolean,Number,String,Object],
      required: true
    },
    art_id: {
      type: [Number, String, Object]
    }
  },
  name: "",
  computed: {
    ...mapState(["user"])
  },
  methods: {
    async attitudehandle() {
      console.log(111111);
      /*
          判断当前的 is_collected=true   收藏   需要发送请求
          判断当前的 is_collected=false  取消收藏
          */
      if (this.user) {
        //  //  已经登录
        //  console.log(this.article.is_collected,888);

        //  if(this.article.is_collected){
        //      //  表示当前是收藏的  ====取消
        //         const  {data:res}=await deleteCollectApi(this.article.art_id)
        //         console.log(res,6666);
        //  }else{
        //      //  表示当前是为收藏的  ====收藏
        //      const  {data:res}=await addCollectApi(this.article.art_id)
        //      console.log(res,7777);
        //  }

        //  this.$emit('collectedlight',!this.article.is_collected)

        //  已经登录
        console.log(this.attitude, 888);
        this.$emit("qqq", this.attitude==1?-1:1);

        if (this.attitude==1) {
          //  表示当前是收藏的  ====取消
          const { data: res } = await deleteLikeApi(this.art_id);
          console.log(res, 6666);
        } else {
          //  表示当前是为收藏的  ====收藏
          const { data: res } = await addLikeApi(this.art_id);
          console.log(res, 7777);
        }
      } else {
        //  没有登录
      }
    }
  }
};
</script>
<style lang="less" scoped>
.collect-container {
  .van-icon {
    color: #ccc;
  }
  .activeCollect {
    color: green;
  }
}
</style>
